using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;

public class PlayerObject : TankBase
{
    public float extraHp = 0;
    public Transform weaponPos;
    // Start is called before the first frame update
    void Start()
    {
        GamePanel.Instance.UpadteHPPanel(originalmaxHp, hp, extraHp);
    }

    // Update is called once per frame
    void Update()
    {
        //控制前进后退
        transform.Translate(Input.GetAxis("Vertical") * Vector3.forward * moveSpeed * Time.deltaTime);
        //控制身体旋转
        transform.Rotate(Input.GetAxis("Horizontal") * Vector3.up * roundSpeed * Time.deltaTime, Space.World);
        //控制炮台旋转
        head.transform.Rotate(Input.GetAxis("Mouse X") * Vector3.up * headRoundSpeed * Time.deltaTime);
        //控制开火
        if (Input.GetMouseButtonDown(0))
        {
            Fire();
        }
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "EnemyBullet")
        {
            BulletObject bullet = other.GetComponent<BulletObject>();
            Debug.Log("玩家受伤");
            //更新血量
            Wound(bullet.fatherObject);
            //更新血条面板
            GamePanel.Instance.UpadteHPPanel(originalmaxHp, hp, extraHp);
        }
    }

    public override void DeadEffect()
    {
        Time.timeScale = 0;
        LosePanel.Instance.ShowMe();
    }
    public override void Wound(TankBase other)
    {
        base.Wound(other);
        //更新血条面板
        GamePanel.Instance.UpadteHPPanel(originalmaxHp, hp, extraHp);
    }
    public void ChangeWeapon(GameObject weaponobj)
    {
        //删除当前武器
        if (nowWeapon != null)
        {
            Destroy(nowWeapon.gameObject);
            nowWeapon = null;
        }
        //切换武器
        //创建武器，位置父对象设置为weaponPos,并且设置保不留Transform（继承父对象的局部坐标系）
        GameObject weapon = Instantiate(weaponobj, weaponPos, false);
        nowWeapon = weapon.GetComponent<WeaponObject>();
        nowWeapon.fatherObject = this;
    }
}
